package com.panghl.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.panghl.domain.ManagerInfo;
import com.panghl.domain.User;
import com.panghl.mapper.MenuMapper;
import com.panghl.mapper.RoleMapper;
import com.panghl.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author panghl
 * @Date 2022/2/14
 **/
@Service
public class ManagerInfoServiceImpl implements ManagerInfoService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private MenuMapper menuMapper;
    @Autowired
    private RoleMapper roleMapper;



    @Override
    public ManagerInfo queryManagerInfoByUserName(String userName) {
        //根据用户名查询用户信息
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(User::getUserName,userName);
        User user = userMapper.selectOne(wrapper);

        List<String> permsList = menuMapper.selectPermsByUserId(user.getId());
        List<String> roleList = roleMapper.selectRoleKeysByUserId(user.getId());
        ManagerInfo managerInfo =new ManagerInfo();
        managerInfo.setUser(user);
        managerInfo.setPermissions(permsList);
        managerInfo.setRoles(roleList);
        return managerInfo;
    }
}
